package com.onlyMe.serialization
{
	import com.flesler.componentas.core.Destroyable;
	
	import flash.utils.ByteArray;
	
	// One time use
	public final class IsleDeserializer implements Destroyable
	{
		private var stream:ByteArray; 
		
		public function IsleDeserializer()
		{
		}
		
		public function deserialize(stream:ByteArray):void
		{
			this.stream = stream;
		}
		
		public function hasNext():Boolean
		{
			return stream.bytesAvailable > 0;
		}
		
		public function getNext():ByteArray
		{
			var ba:ByteArray = new ByteArray();
			var len:int = stream.readShort();
			stream.readBytes(ba, 0, len);
			ba.position = 0;
			return ba;
		}
		
		public function destroy():void
		{
			stream = null;
		}

	}
}